package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.servlet;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.dao.ParametriDao;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Parametri;

@SuppressWarnings("serial")
public class PromenaParametaraKontroler extends HttpServlet {

	@EJB
	private ParametriDao cParametriDao;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		Parametri tekuci = cParametriDao.tekuci();
		req.setAttribute("parametri", tekuci);
		getServletContext().getRequestDispatcher("/jsp/promenaParametara.jsp")
				.forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		float a = Float.parseFloat(req.getParameter("a"));
		float b = Float.parseFloat(req.getParameter("b"));
		float c = Float.parseFloat(req.getParameter("c"));

		Parametri novi = new Parametri(a, b, c);
		cParametriDao.sacuvaj(novi);
		getServletContext().getRequestDispatcher("/jsp/prikazVoznji.jsp")
				.forward(req, resp);
	}
}
